The present invention relates to a Java Virtual Machine adapted to load native code libraries stored in archived files.
JAVA (TM) applications are written as groups of classes, and typically execution of an application begins with the Java Virtual Machine (JVM) using a class loader to instantiate a main class, which in turn creates various objects requiring the instantiation of further classes. Class files are stored in various directory structures indicated by a classpath environmental parameter. In a stand-alone JVM, the class loader looks to classpath, an environmental parameter, which usually includes a sub-directory containing all the dedicated classes for a particular application, to determine where to look for classes. In a browser JVM, classpath also extends to the remote server from which an application (applet) is downloaded.
In an effort to cope with Java applications which have increased in complexity and so in size, it has become common for developers to package classes required for an application into one or more archived files, such as JAR files or ZIP files. Archived files are significantly more compact than their uncompressed component class files and so are particularly useful for deploying an application across a network, such as the Internet.
Archived files are stored in the directories of classpath or they can be individually designated within classpath. In the Figure, the classpath shown includes: a sub-directory structure in which class and archived files a to f are stored; and a direct reference to h.jar. When the JVM needs to instantiate a class, the class loader searches through the classpath directories, including class or archived files, and classpath archived files to find the required class file or to determine if such a class file is stored within an archived file. If a class is stored within an archive, as in the case of classes db and dc, then the JVM uncompresses the class file from the archive directly into memory. Thus, the unarchived classes are not written to disk and, in the case of network applications, far less time is lost uncompressing the file than downloading an uncompressed class from a remote server.
Although, Java provides a means for developing applications in a platform independent manner, some application developers nonetheless either need or find it easier to use native code. In the case of Java applications written for the MICROSOFT WINDOWS(trademark) suite of platforms, such native code typically comprises dynamic link libraries (DLLs) accessed through the Java Native Interface (JNI).
When an application employs native functionality, it should indicate this to the JVM before calling such methods by calling the loadLibrary method on either the java.lang.System or java.lang.Runtime object. Alternatively, the JVM can call the loadLibrary method in response to a native method call to a library which has not been loaded. In any case, loadLibrary operates in the same manner. The loadLibrary method is passed a string comprising the name of the native code library to be loaded. Although implementation specific, generally the method then searches through a library path (analogous to classpath) for the appropriate library. In the Figure, the library path includes a sub-directory structure including DLLs aa to cc and a cache sub-directory whose purpose will be explained later. On finding a library, it is loaded into memory and its methods, for example, methods bba . . . bbc from library bb.dll, become exposed for use within the Java application.
While this functionality in itself is quite useful, it does means that library files must be available to the JVM, in the same manner as to platform dependent applications, before applications availing of such libraries are executed. This does not pose a problem where default native code libraries are accessed, but more and more developers are implementing applications partially in Java and partially in native format. This means that for network applications, in particular, the native libraries must be installed before the network application can execute, and this places a high deployment cost on such applications.
There has been a clamour from developers seeking to place native code in archived files, for example, d.jar, which could then be deployed with the classes comprising the remainder of the Java application. This would mean that Java applications could be deployed and updated in a single step as they are required by users, thus making the functionality of native code more accessible to both developers and users.
Notwithstanding, this functionality has not been made available to date in a Java Virtual Machine.
The present invention, however, provides a Java Virtual Machine according to a Java virtual Machine comprising: means, responsive to a request to instantiate a class, for searching a first path in which class files and archived files are stored; means, responsive to locating a requested class file in said first path or within an archived file in said first path, for loading said class into memory; means, responsive to a request to load a native code library, for searching a second path in which library files are stored; means, responsive to locating a requested library file in said second path, for loading said library into memory; wherein said means for searching a second path is adapted to search said first path; and in that said means for loading a library is responsive to locating a requested library file in an archived file in said first path to load said library into memory.
It will be seen that in spite of adapting the JVM to include the platform dependent functionality of the invention, whereby archived files may include native code, the JVM is no more platform dependent than conventional JVM""s, which allow applications to make native method calls.